package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.UserUtil;
import cn.stylefeng.guns.modular.api.entity.Check;
import cn.stylefeng.guns.modular.api.model.params.CheckParam;
import cn.stylefeng.guns.modular.api.model.result.CheckResult;
import cn.stylefeng.guns.modular.api.service.CheckService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 盘点控制器
 *
 * @author wusonghe
 * @Date 2019-08-31 00:07:13
 */
@Controller
@RequestMapping("/api/check")
@Api(tags = "盘点管理", description = "盘点管理")
public class CheckController extends BaseController {

    private String PREFIX = "/check";

    @Autowired
    private CheckService checkService;

    /**
     * 跳转到主页面
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/check.html";
    }

    /**
     * 新增页面
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/check_add.html";
    }

    /**
     * 编辑页面
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/check_edit.html";
    }

    /**
     * 新增接口
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
	@PostMapping("/addItem")
    @ResponseBody
    @ApiOperation(value = "新增接口", notes = "新增", response = ResponseData.class)
    @ApiResponses({@ApiResponse(code = 200, message = "新增", response = ResponseData.class)})
    public ResponseData addItem(CheckParam checkParam) {
        this.checkService.add(checkParam);
        return ResponseData.success();
    }

    /**
     * 更新接口
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
	@PostMapping("/editItem")
    @ResponseBody
//    @ApiOperation(value = "更新接口", notes = "更新", response = ResponseData.class)
    @ApiResponses({@ApiResponse(code = 200, message = "更新", response = ResponseData.class)})
    public ResponseData editItem(CheckParam checkParam) {
        this.checkService.update(checkParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
	@PostMapping("/delete")
    @ResponseBody
//    @ApiOperation(value = "删除接口", notes = "删除", response = ResponseData.class)
    @ApiResponses({@ApiResponse(code = 200, message = "详情", response = ResponseData.class)})
    public ResponseData delete(Integer checkId) {
        CheckParam checkParam = new CheckParam();
        checkParam.setCheckId(checkId);
        this.checkService.delete(checkParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
	@PostMapping("/detail")
    @ResponseBody
    @ApiOperation(value = "详情接口", notes = "详情", response = CheckResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "详情", response = CheckResult.class)})
    public ResponseData detail(CheckParam checkParam) {
        Check detail = this.checkService.getById(checkParam.getCheckId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wusonghe
     * @Date 2019-08-31
     */
	@PostMapping(value = "/list")
    @ResponseBody
    @ApiOperation(value = "列表接口", notes = "列表", response = CheckResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "列表", response = CheckResult.class)})
    public LayuiPageInfo list(CheckParam checkParam) {
        return this.checkService.findPageBySpec(checkParam);
    }

}


